package com.kfgj.hkp.common.dataaccess.redis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class StringRedisService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    private ValueOperations getOperation(){
        return stringRedisTemplate.opsForValue();
    }

    public void put(final String key,final String value) {
        getOperation().set(key,value);
    }

    public Object get(final String key) {
        return getOperation().get(key);
    }

    public Boolean exist(final String key) {
        return stringRedisTemplate.hasKey(key);
    }

    public void expire(final String key,final Long expireSeconds) {
        stringRedisTemplate.expire(key,expireSeconds, TimeUnit.SECONDS);
    }
}

































